package com.example.mr5.money.main.myexpense;/**
 * Created by Mr.5
 * Date：2016/9/13.
 * Time：22:34
 */

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.mr5.money.R;
import com.example.mr5.money.model.Record;

import java.util.List;

/**
 * Created by Mr.5 
 * Date：2016/9/13.
 * Time：22:34
 */
public class MyExpenseListAdapter extends BaseAdapter {

    private Context context;
    private List<Record> recordList;

    public MyExpenseListAdapter(Context context, List<Record> recordList){
        this.context = context;
        this.recordList = recordList;
    }

    @Override
    public int getCount() {
        return recordList.size();
    }

    @Override
    public Record getItem(int position) {
        return recordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null){
            holder = new Holder();
            convertView = View.inflate(context,R.layout.item_record_list,null);
            holder.tvMainTitle = (TextView) convertView.findViewById(R.id.main_title);
            holder.tvSubTitle = (TextView) convertView.findViewById(R.id.sub_title);
            holder.tvAmount = (TextView) convertView.findViewById(R.id.amount);
            holder.tvDate = (TextView) convertView.findViewById(R.id.date);
            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }
        holder.tvMainTitle.setText(recordList.get(position).getMainTitle());
        holder.tvSubTitle.setText(recordList.get(position).getSubTitle());
        holder.tvAmount.setText("-"+recordList.get(position).getAmount()+"元");
        holder.tvAmount.setTextColor(context.getResources().getColor(R.color.money_red));
        holder.tvDate.setText(recordList.get(position).getDate());

        return convertView;
    }

    private class Holder{
        private TextView tvMainTitle;
        private TextView tvSubTitle;
        private TextView tvAmount;
        private TextView tvDate;
    }
}
